package com.example.jiaopin.Controller;
import com.example.jiaopin.Service.CourseService;
import com.example.jiaopin.model.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/courses")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @GetMapping("/{courseID}")
    public Course getCourseById(@PathVariable Integer courseID) {
        return courseService.getCourseById(courseID);
    }

    @PostMapping("/")
    public void insertCourse(@RequestBody Course course) {
        courseService.insertCourse(course);
    }

    @PutMapping("/{courseID}")
    public void updateCourse(@PathVariable Integer courseID, @RequestBody Course course) {
        course.setCourseID(courseID);
        courseService.updateCourse(course);
    }

    @DeleteMapping("/{courseID}")
    public void deleteCourse(@PathVariable Integer courseID) {
        courseService.deleteCourse(courseID);
    }
}